﻿using System.Xml.Linq;

namespace SchemaGen.Xsd
{
    public class SAttribute : SEntityBase
    {
        public SSimpleType Restriction { get; set; }
        public bool IsRequired { get; set; }

        public SAttribute(string name)
            : base(SNames.Elements.Attribute, name) { }

        internal override XElement Create()
        {
            var result = base.Create();

            if (IsRequired) result.Add(new XAttribute("use", "required"));

            if (Restriction != null)
                result.Add(new XElement(SNames.Elements.SimpleType,
                    Restriction.Create()));

            return result;
        }
    }
}
